
using Microsoft.EntityFrameworkCore;
using SmartWMS.API;
using SmartWMS.API.Extensions;
using SmartWMS.Common.Const;
using SmartWMS.EntityFramework;
using Yitter;
using Yitter.IdGenerator;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
YitIdHelper.SetIdGenerator(new IdGeneratorOptions());

builder.Services.AddSignalR();
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.SwaggerRegister();
builder.Services.CorsRegister();
builder.Services.ServicesRegister();

//配置注入雪花
YitIdHelper.SetIdGenerator(new IdGeneratorOptions());  

builder.WebHost.UseKestrel(options =>
{
    options.Limits.MaxConcurrentConnections = 100;
    options.Limits.MaxConcurrentUpgradedConnections = 100;
    options.Limits.MaxRequestBodySize = 52428800;
});
builder.WebHost.UseIIS();

var app = builder.Build();

app.UseSwagger(c =>
{
    c.RouteTemplate = "swagger/{documentname}/swagger.json";
});

app.UseSwaggerUI(options =>
{
    options.SwaggerEndpoint("/swagger/XTong/swagger.json", "系统设置");
    options.SwaggerEndpoint("/swagger/BasicsDatum/swagger.json", "基础数据");
    options.SwaggerEndpoint("/swagger/Business/swagger.json", "业务管理");
    options.SwaggerEndpoint("/swagger/Statement/swagger.json", "报表管理");
    options.SwaggerEndpoint("/swagger/Warehouse/swagger.json", "仓库管理");
    options.SwaggerEndpoint("/swagger/Statement/swagger.json", "仓库管理");
    options.SwaggerEndpoint("/swagger/Finance/swagger.json", "财务管理");
});
//李子恒
// Configure the HTTP request pipeline. 
if (app.Environment.IsDevelopment())
{
    //app.UseSwagger();
    //app.UseSwaggerUI();
}
app.UseCors(option => option.WithOrigins("http://localhost:8080").AllowCredentials().AllowAnyMethod().AllowAnyHeader());
//3、配置前端接口
app.MapHub<SmartWMS.Common.ChatHub>("/chatHub");

app.UseCors(AssemblyConst.CORS_POLICY);

app.UseHttpsRedirection();

app.UseAuthorization();

app.UseStaticFiles();

app.MapControllers();

app.Run();